//
//  ReweetedStatusView.swift
//  ydy_weibo
//
//  Created by 杨德勇 on 16/7/18.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

import UIKit
import SnapKit

class ReweetedStatusView: UIView {
    var bottomConstrains : Constraint?
   
    
    //MARK:-
    //MARK:4.源数据
    var retweetedStatus:Status?{
        didSet{
            reweetedLabel.text = retweetedStatus?.text
            self.bottomConstrains?.uninstall()
            
            if let picurls = retweetedStatus?.imageURLs where picurls.count > 0{
                pictureView.imageURLs = picurls
                pictureView.hidden = false
                
                self.snp_updateConstraints(closure: { (make) in
                    self.bottomConstrains = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
                    
                })
            }else{
                //无图片情况
                pictureView.hidden = false
                
                self.snp_updateConstraints(closure: { (make) in
                    self.bottomConstrains = make.bottom.equalTo(reweetedLabel.snp_bottom).constraint
                })
            }
            
        }
    }

    
    
    //MARK:-
    //MARK:3.init
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
    //MARK:-
    //MARK:2.setupUI
    private func setupUI(){
        addSubview(reweetedLabel)
        addSubview(pictureView)
        
        reweetedLabel.snp_makeConstraints { (make) in
            make.top.equalTo(snp_top).offset(StatusCellMargin)
            make.left.equalTo(snp_left).offset(StatusCellMargin)
            
        }
        
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(reweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(reweetedLabel.snp_left)
        }
        
        
        self.snp_makeConstraints { (make) in
            self.bottomConstrains = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }
    }

    //MARK:-
    //MARK:1.懒加载所有控件
    private lazy var reweetedLabel:UILabel = UILabel(title: "我是转发微博", fontSize: 14, color: UIColor.darkGrayColor(), margin: StatusCellMargin)
    private lazy var pictureView :StatusPictureView = StatusPictureView()

}
